<template>
  <div class="app-container">
    <input type="text" autocomplete="off" v-model="stationCode" placeholder="展点id">
    <input type="text" autocomplete="off" v-model="stationName" placeholder="展点名称">
    <button type="button" @click="fetchData">
      <span>查询</span>
    </button>
    <el-table v-loading="listLoading" :data="list" element-loading-text="Loading" border fit highlight-current-row>
      <el-table-column align="center" label="id" width="95">
        <template slot-scope="scope">
          {{ scope.$index }}
        </template>
      </el-table-column>
      <el-table-column label="station_code">
        <template slot-scope="scope">
          {{ scope.row.stationCode }}
        </template>
      </el-table-column>
      <el-table-column label="station_name" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.stationName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="station_mongo_code" align="center">
        <template slot-scope="scope">
          {{ scope.row.stationMongoCode }}
        </template>
      </el-table-column>
    </el-table>

    <el-button type="text" @click="dialogVisible = true">新增测试展点</el-button>

    <el-dialog title="新增测试展点" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">

      <el-form ref="form" :model="form" label-width="110px">
        <el-form-item label="展点名称">
          <el-input v-model.trim="form.name"></el-input>
        </el-form-item>
        <el-form-item label="展点code">
          <el-input v-model.trim="form.stationCode"></el-input>
        </el-form-item>
        <el-form-item label="展点MongoDB">
          <el-input v-model.trim="form.mongocode"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="createStation">立即创建</el-button>
          <el-button>取消</el-button>
        </el-form-item>
      </el-form>
      
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>

    
  </div>
</template>

<script>
import { getList } from '@/api/table'
import { addStation } from '@/api/table'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: null,
      listLoading: true,
      stationCode: "",
      stationName: null,
      dialogVisible: false,
      form: {
        name: '',
        stationCode: '',
        mongocode: ''
      }
    }
  },
  created() {
    this.fetchData()
    // this.createStation()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      getList({
        "stationCode": this.stationCode,
        "stationName": this.stationName
      }).then(response => {
        console.log(response)
        this.list = response.data
        this.listLoading = false
      })
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => { });
    },
    createStation() {
      console.log('submit!')
      // console.log(this.form.name)
      addStation(
        {
          "stationCode": this.form.stationCode,
          "stationName": this.form.name,
          "stationMongoCode": this.form.mongocode
        }
      ).then(response => {
        console.log(response)
        // this.list = response.data
        // this.listLoading = false
      })
    }

  }
}
</script>

<style></style>